<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('修改模板配置')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-template-edit" th:object="${template}">
    <input type="hidden" id="templateId" name="templateId" th:field="*{templateId}">
    <div class="form-group">
      <label class="col-sm-3 control-label is-required">文件名：</label>
      <div class="col-sm-8">
        <input id="templateName" name="templateName" th:field="*{templateName}" class="form-control" type="text"
               required>
        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 模版名称同时作为生成文件的文件名（包括后缀名）</span>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label is-required">模版类型：</label>
      <div class="col-sm-8">
        <div class="radio-box" th:each="dict : ${@dict.getType('template_type')}">
          <input type="radio" th:id="${dict.dictCode}" name="templateType" th:value="${dict.dictValue}" th:field="*{templateType}">
          <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label is-required">排序：</label>
      <div class="col-sm-8">
        <input class="form-control" type="text" name="templateSort" th:field="*{templateSort}" required>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label is-required">启用状态：</label>
      <div class="col-sm-8">
        <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
          <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
          <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">备注信息：</label>
      <div class="col-sm-8">
        <textarea id="remark" name="remark" class="form-control" th:field="*{remark}"></textarea>
      </div>
    </div>
  </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
  var prefix = ctx + "tool/template";

  $("#form-template-edit").validate({
    onkeyup: false,
    rules: {
      templateName: {
        remote: {
          url: prefix + "/checkTemplateUnique",
          type: "post",
          dataType: "json",
          data: {
            "templateId": function () {
              return $("#templateId").val();
            },
            "templateType": function () {
              return $.common.trim($("#templateType").val());
            },
            "templateName": function () {
              return $.common.trim($("#templateName").val());
            }
          },
          dataFilter: function (data, type) {
            return $.validate.unique(data);
          }
        }
      }
    },
    messages: {
      "templateName": {
        remote: "该模板名称已经存在"
      }
    },
    focusCleanup: true
  });

  function submitHandler() {
    if ($.validate.form()) {
      $.operate.save(prefix + "/edit", $('#form-template-edit').serialize());
    }
  }
</script>
</body>
</html>
